package com.langsin.crmpro.action;

import static com.langsin.crmpro.utils.STool.$;

import com.langsin.crmpro.base.BaseAction;
import com.langsin.crmpro.manager.DictionaryDetailManager;
import com.langsin.crmpro.manager.DictionaryManager;
import com.langsin.crmpro.manager.DictionaryManagerImpl;
import com.langsin.crmpro.model.SDictionaryClass;
import com.langsin.crmpro.model.SDictionaryDetail;

public class DictionaryDetailAction extends BaseAction{

	private static final long serialVersionUID = 9072053369762804503L;
	
	private String updateData;
	
	private Integer sort;
	
	private String code;
	
	private String newDict;
	
	private String id;

	private DictionaryDetailManager dictionaryDetailManager;
	
	public String updateDictionaryDetails() throws Exception
	{
		dictionaryDetailManager.updateDictionaryDetails(this.updateData, this.newDict, this.code);
		
		return SUCCESS;
	}
	
	public String upSort() throws Exception
	{
		Integer highSort = (Integer)this.dictionaryDetailManager.findUpSort(sort, code);
		
		SDictionaryDetail highDict = null;
		SDictionaryDetail lowDict = null;
		
		if( $(highSort))
		{
			highDict = (SDictionaryDetail)this.dictionaryDetailManager.findDictDetailByCode(highSort);
			lowDict = (SDictionaryDetail)this.dictionaryDetailManager.findDictDetailByCode(sort);
			
			highDict.setSort(sort);
			lowDict.setSort(highSort);
			
			this.dictionaryDetailManager.updateSorts(highDict, lowDict);
		}
		
		
		return SUCCESS;
	}
	
	public String downSort() throws Exception
	{
		Integer lowSort = (Integer)this.dictionaryDetailManager.findDownSort(sort, code);
		
		SDictionaryDetail highDict = null;
		SDictionaryDetail lowDict = null;
		
		if( $(lowSort))
		{
			lowDict = (SDictionaryDetail)this.dictionaryDetailManager.findDictDetailByCode(lowSort);
			highDict = (SDictionaryDetail)this.dictionaryDetailManager.findDictDetailByCode(sort);
			
			highDict.setSort(lowSort);
			lowDict.setSort(sort);
			
			this.dictionaryDetailManager.updateSorts(highDict, lowDict);
		}
		
		
		return SUCCESS;
	}
	
	public String del() throws Exception
	{
		this.dictionaryDetailManager.delDictionaryDetailsById(this.id);
		
		return SUCCESS;
	}

	public String getUpdateData()
	{
		return updateData;
	}

	public DictionaryDetailManager getDictionaryDetailManager()
	{
		return dictionaryDetailManager;
	}

	public void setUpdateData(String updateData)
	{
		this.updateData = updateData;
	}

	public void setDictionaryDetailManager(
			DictionaryDetailManager dictionaryDetailManager)
	{
		this.dictionaryDetailManager = dictionaryDetailManager;
	}

	public Integer getSort()
	{
		return sort;
	}

	public String getCode()
	{
		return code;
	}

	public void setSort(Integer sort)
	{
		this.sort = sort;
	}

	public void setCode(String code)
	{
		this.code = code;
	}
	
	public String getNewDict()
	{
		return newDict;
	}

	public void setNewDict(String newDict)
	{
		this.newDict = newDict;
	}
	

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}
	
	
}
